package com.learn.aop.locator.support;

import cn.hutool.core.collection.CollectionUtil;
import com.learn.aop.locator.ProxyMetaDefinitionLocator;
import com.learn.aop.model.ProxyMetaDefinition;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:    java类作用描述
 * @author:         MI
 * @email:          448341911@qq.com
 * @createTime:     2024/1/8 15:48
 * @updateUser:     cong zhi
 * @updateTime:     2024/1/8 15:48
 * @updateRemark:   修改内容
 * @version:        v1.0
 */
@RequiredArgsConstructor
public class CompositeProxyMetaDefinitionLocator implements ProxyMetaDefinitionLocator {

    private final List<ProxyMetaDefinitionLocator> delegates;

    @Override
    public List<ProxyMetaDefinition> getProxyMetaDefinitions() {
        List<ProxyMetaDefinition> compositeProxyMetaDefinitions = new ArrayList<>();
        for (ProxyMetaDefinitionLocator delegate : delegates) {
            List<ProxyMetaDefinition> proxyMetaDefinitions = delegate.getProxyMetaDefinitions();
            if(CollectionUtil.isNotEmpty(proxyMetaDefinitions)){
                compositeProxyMetaDefinitions.addAll(proxyMetaDefinitions);
            }

        }
        return compositeProxyMetaDefinitions;
    }
}
